package com.wps.wdztv6.api.request;

import com.mybatisflex.core.query.QueryWrapper;
import com.wps.wdztv6.entity.TemplateFile;
import com.wps.wdztv6.entity.table.TemplateFileTableDef;
import com.wps.wdztv6.vo.PageParams;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.validation.constraints.NotEmpty;


@Data
@EqualsAndHashCode(callSuper = true)
public class TemplateFileQuery extends PageParams<TemplateFile> {
    private Integer id;
    private String code;
    private String templateFileName;

    private String category;
    @NotEmpty(message = "系统来源不能空")
    private String source;

    public QueryWrapper queryWrapperBuild() {
        QueryWrapper queryWrapper = QueryWrapper.create();

        if (null != id) {
            queryWrapper.and(TemplateFileTableDef.TEMPLATE_FILE.ID.eq(id));
            return queryWrapper;
        }
        
        queryWrapper.and(TemplateFileTableDef.TEMPLATE_FILE.CODE.eq(code))
                .and(TemplateFileTableDef.TEMPLATE_FILE.SOURCE.eq(source))
                .and(TemplateFileTableDef.TEMPLATE_FILE.CATEGORY.eq(category))
                .and(TemplateFileTableDef.TEMPLATE_FILE.TEMPLATE_FILE_NAME.likeLeft(templateFileName));
        return queryWrapper;
    }
}
